

public class CheckingAcnt extends Account
{

	@Override
	public void deposit(double amount)
	{
		balance += amount;
	}

	@Override
	public double withdraw(double amount)
	{
		if( balance < amount)
		{
			// withdraw some from savings
			
			// TODO: code to be removed seems like statements 
			//       had no effect when adding and subtracting, 
			//       unless it was only acting up in my machine
			//BigDecimal need = new BigDecimal(0.0);
			//need.add(lowThreshold);
			//need.add(amount);
			//need.subtract(balance);
			//balance = balance.add(underFlowAccount.withdraw(need)));
			//balance = balance.add(underFlowAccount.withdraw(lowThreshold.add(amount).subtract(balance)));
			balance += underFlowAccount.withdraw(lowThreshold + amount - balance);
		}
		balance -= amount;
		
        return amount;
	}
	
	private void balanceAccounts() throws IllegalStateException
	{
		if(balance > highThreshold)
		{
			// add excess to overFlowAccount
			double excess = balance - highThreshold;
			balance -= excess;
			overFlowAccount.deposit(excess);
		}
		if (balance < lowThreshold)
		{
			// draw enough from underflow account reach low threshold
			double need = lowThreshold - balance;
			double actualWithdrawn = underFlowAccount.withdraw(need);
			balance += actualWithdrawn;
		}
	}

	@Override
	public void doTimeTick() throws IllegalStateException
	{
		// TODO Auto-generated method stub
		balanceAccounts();
		
	}

}
